const name = 'nfgogo'; // page title
// eslint-disable-next-line @typescript-eslint/no-var-requires
const tsImportPluginFactory = require('ts-import-plugin');

module.exports = {
  // publicPath: './',
  parallel: false, // 是否为 Babel 或 TypeScript 使用 thread-loader。该选项在系统的 CPU 有多于一个内核时自动启用，仅作用于生产构建。
  devServer: {
    port: 8080,
    open: true,
    disableHostCheck: true, // 关闭host检查
    overlay: {
      warnings: false,
      errors: true,
    },
    proxy: {
      [process.env.VUE_APP_BASE_API]: {
        target: 'http://39g541j049.qicp.vip/', // http://changlaiai.xicp.net:21542/ http://www.nfgogo.com:8086/  http://39g541j049.qicp.vip/
        changeOrigin: true,
        pathRewrite: {
          [`^${process.env.VUE_APP_BASE_API}`]: '',
        },
      },
    },
  },
  transpileDependencies: [
    'vuetify',
  ],
  configureWebpack: {
    name,
    devtool: 'source-map',
    module: {
      rules: [
        {
          test: /\.(jsx|tsx|js|ts)$/,
          loader: 'ts-loader',
          options: {
            transpileOnly: true,
            getCustomTransformers: () => ({
              before: [tsImportPluginFactory(
                {
                  libraryName: 'vant',
                  libraryDirectory: 'es',
                  style: (tit) => `${tit}/style/less`, // 配置vant主题文件
                },
              )],
            }),
            compilerOptions: {
              module: 'es2015',
            },
          },
          exclude: /node_modules/,
        },
      ],
    },
  },
  chainWebpack(config) {
    // set preserveWhitespace
    config.module
      .rule('vue')
      .use('vue-loader')
      .loader('vue-loader')
      .tap((options) => {
        options.compilerOptions.preserveWhitespace = true;
        return options;
      })
      .end();
    config
    // https://webpack.js.org/configuration/devtool/#development
      .when(process.env.NODE_ENV === 'development',
        (config) => config.devtool('cheap-source-map'));
  },
};
